package com.hongyuan.coach.ui.home.view_mode;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.coach.base.ItemViewModel;
import com.hongyuan.coach.data.Constants;
import com.hongyuan.coach.ui.home.beans.TopTimeBean;
import com.hongyuan.coach.utils.TimeUtil;

public class HomeTopItemViewModel extends ItemViewModel<HomeViewMode> {

    public ObservableField<TopTimeBean> entity = new ObservableField<>();

    public HomeTopItemViewModel(@NonNull HomeViewMode viewModel, TopTimeBean bean) {
        super(viewModel);
        entity.set(bean);
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(() -> {
        if(viewModel.itemViewModel != this){
            viewModel.itemViewModel.entity.get().setSelect(false);
            viewModel.itemViewModel.entity.notifyChange();

            viewModel.itemClick(this);

            viewModel.curPage = viewModel.FIRST_PAGE;

            viewModel.clearParams().setParams("start_date", entity.get().getNow_day())
                    .setParams("end_date", TimeUtil.getNextDay(1,entity.get().getNow_day(),TimeUtil.dateFormatYMD))
                    .setParams("state_str","1");
            viewModel.requestData(Constants.GET_COACH_APPOINTMENT_COURSE_PRIVITE_LIST);
        }
    });
}
